package demo3;

public class Main {
    public static void main(String[] args) {
        Manager jinli = new CommonManager("金利");
        Manager zongjian = new Majordomo("宗剑");
        Manager zhongjingli = new GeneralManager("钟静丽");
        jinli.setSuperior(zongjian);
        zongjian.setSuperior(zhongjingli);

        Request request1 = new Request();
        request1.setRequestType("请假");
        request1.setRequestContent("小菜请假");
        request1.setNumber(1);
        jinli.RequestApplications(request1);

        Request request2 = new Request();
        request2.setRequestContent("小王请假");
        request2.setRequestType("请假");
        request2.setNumber(100);
        jinli.RequestApplications(request2);

        Request request3 = new Request();
        request3.setRequestType("加薪");
        request3.setRequestContent("小菜加薪");
        request3.setNumber(400);
        jinli.RequestApplications(request3);

        Request request4 = new Request();
        request4.setRequestType("请假");
        request4.setRequestContent("小吴请假");
        request4.setNumber(5);
        jinli.RequestApplications(request4);

        Request request5 = new Request();
        request5.setRequestType("加薪");
        request5.setRequestContent("老李加薪");
        request5.setNumber(1000);
        jinli.RequestApplications(request5);
    }
}

class Request{
    //申请类别
    private String requestType;

    public String getRequestType() {
        return requestType;
    }

    public void setRequestType(String requestType) {
        this.requestType = requestType;
    }
    private String requestContent;

    public String getRequestContent() {
        return requestContent;
    }

    public void setRequestContent(String requestContent) {
        this.requestContent = requestContent;
    }

    private int number;

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

}
abstract class Manager{
    protected String name;
    protected Manager superior; //管理者的上级

    public Manager(String name){
        this.name = name;
    }

    public void setSuperior(Manager superior) {
        this.superior = superior;
    }
    //申请请求
    abstract public void RequestApplications(Request request);
}

class CommonManager extends Manager{
    //经理

    public CommonManager(String name) {
        super(name);
    }

    @Override
    public void RequestApplications(Request request) {
        if(request.getRequestType()=="请假"&&request.getNumber()<=3){
            System.out.println( name + "经理批准：" +request.getRequestContent()+"数量"+request.getNumber()+"天");
        }else{
            if(superior != null){
                superior.RequestApplications(request);
            }
        }
    }
}

class Majordomo extends Manager{
    public Majordomo(String name) {
        super(name);
    }

    @Override
    public void RequestApplications(Request request) {
        if(request.getRequestType()=="请假"&&request.getNumber()<=7){
            System.out.println( name + "总监批准：" +request.getRequestContent()+"数量"+request.getNumber()+"天");
        }else{
            if(superior != null){
                superior.RequestApplications(request);
            }
        }
    }

}

//总经理
class GeneralManager extends Manager{
    public GeneralManager(String name) {
        super(name);
    }

    @Override
    public void RequestApplications(Request request) {
        if(request.getRequestType() == "请假"){
            System.out.println(name + " 总经理批准请假"+request.getRequestContent()+"数量"+request.getNumber()+"天");
        }else if(request.getRequestType() == "加薪"&&request.getNumber()<=500){
            System.out.println(name + " 总经理批准加薪"+request.getRequestContent()+"数量"+request.getNumber()+"元");
        }else if(request.getRequestType()=="加薪"&&request.getNumber()>500){
            System.out.println(name+"总经理说:"+request.getRequestContent()+"再说吧");
        }
    }
}